package com.yun.algorithmproblem.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Leetcode447 {
    public int numberOfBoomerangs(int[][] points) {
        int res = 0;
        int len = points.length;
        Map<Integer, Integer> cnt = new HashMap<>();
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                if (i == j) {
                    continue;
                }
                int dis = (points[i][0] - points[j][0]) * (points[i][0] - points[j][0]) +
                        (points[i][1] - points[j][1]) * (points[i][1] - points[j][1]);
                int cur=cnt.getOrDefault(dis,0);
                cnt.put(dis,cur+1);
                if(cur!=0){
                    res+=2*cur;
                }
            }
            cnt.clear();
        }
        return res;
    }
}
